﻿using UnityEngine;
using System.Collections;
using System;
using System.Net.Sockets;
using System.Net;

public class UDPController : Singleton<UDPController>
{

    private UDPNetConnector connector;

    public override void Init()
    {
        base.Init();
    }

    public override void UnInit()
    {
        base.UnInit();

        if (connector != null)
            connector.Dispose();
    }

    public void NetworkPrepare(ushort port,string remoteIp)
    {
        if (connector == null)
            connector = new UDPNetConnector(remoteIp, port);
    }

    public void Open()
    {
        connector.Open();
    }

    public void Close()
    {
        connector.Close();
    }

    public void SendData(byte[] data,int port,string ip)
    {
        connector.SendMessage(data,port,ip);
    }

    private void OnOneMsgRecived(byte[] buffer)
    {
        NetManager.Instance.ProcessData(buffer);
    }
}
